// 这个文件专门存放关于列表的所有接口
const Router = require('koa-router')
const home = new Router()

const db = require('../utils/db.js')
const { baseUrl } = require('../baseUrl/index')


// 写对应的接口
home.get('/', async (ctx) => {
  ctx.body = "首页"
})

home.get('/banner', async (ctx) => {
  let data = await new Promise((resolve, reject) => {
    let sqlLang = `select * from banner`
    db.query(sqlLang, (err, data) => {
      if (err) reject(err)
      data.map(item => {
        item.imgUrl = baseUrl + item.imgUrl
      })
      resolve(data)	// 返回拿到的数据
    })
  })
  ctx.body = data
})

home.get('/footer', async (ctx) => {
  ctx.body = "首页-底部"
})


module.exports = home